package com.zero.service.impl;

import com.zero.entity.District;
import com.zero.mapper.DistrictMapper;
import com.zero.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Author: Zero
 * @Description:  处理省市区业务层接口的实现类
 * @Date: 2022/10/17 20:21
 * @Param:
 * @return:
 **/
@Service
public class IDistrictServiceImpl implements IDistrictService {
    @Autowired
    private DistrictMapper districtMapper;

    /**
     * Description : 根据父代号查询省市区信息
     * @date 2022/10/17
     * @param parent 父代号
     * @return
     **/
    @Override
    public List<District> getSpecifyDistrictByParent(String parent) {
        List<District> districts = districtMapper.queryDistrictByParent(parent);

        //过滤无效字段数据，提高传输效率
        for (District ad: districts) {
            ad.setId(null);
            ad.setParent(null);
        }

        //返回数据
        return districts;
    }

    /**
     * Description : 根据code查询省市区名字
     * @date 2022/10/17
     * @param code 省市区的code
     * @return java.lang.String
     **/
    @Override
    public String getNameByCode(String code) {
        return districtMapper.queryDistrictByCode(code);
    }
}
